import Main from '@/components/main'
import parentView from '@/components/parent-view'

/**
 * iview-admin中meta除了原生参数外可配置的参数:
 * meta: {
 *  title: { String|Number|Function }
 *         显示在侧边栏、面包屑和标签栏的文字
 *         使用'{{ 多语言字段 }}'形式结合多语言使用，例子看多语言的路由配置;
 *         可以传入一个回调函数，参数是当前路由对象，例子看动态路由和带参路由
 *  hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
 *  notCache: (false) 设为true后页面不会缓存
 *  access: (null) 可访问该页面的权限数组，当前路由设置的权限会影响子路由
 *  icon: (-) 该页面在左侧菜单、面包屑和标签导航处显示的图标，如果是自定义图标，需要在图标名称前加下划线'_'
 *  beforeCloseName: (-) 设置该字段，则在关闭当前tab页时会去'@/router/before-close.js'里寻找该字段名对应的方法，作为关闭前的钩子函数
 * }
 */

export default [
  {
    path: '/login',
    name: 'login',
    meta: {
      title: 'Login - 登录',
      hideInMenu: true
    },
    component: () => import('@/view/login/login.vue')
  },
  {
    path: '/',
    name: '_home',
    redirect: '/home',
    component: Main,
    meta: {
      hideInMenu: true,
      notCache: true
    },
    children: [
      {
        path: '/home',
        name: 'home',
        meta: {
          hideInMenu: true,
          title: '首页',
          notCache: true,
          icon: 'md-home'
        },
        component: () => import('@/view/single-page/home')
      }
    ]
  },
  {
    path: '/',
    name: 'home',
    redirect: '/home',
    meta: {
      title: '首页',
      icon: 'ios-home'
    }
  },
  {
    path: '/user',
    name: 'user',
    meta: {
      hideInBread: true,
      access: ['user']
    },
    component: Main,
    children: [
      {
        path: 'index',
        name: 'index',
        meta: {
          icon: 'md-contacts',
          title: '用户管理',
          access: ['user.list']
        },
        component: () => import('@/view/users'),
      }
    ]
  },
  {
    path: '/workspace',
    name: 'workspace',
    meta: {
      title: '部门管理',
      icon: 'ios-cloudy',
      access: ['workspace']
    },
    component: Main,
    children: [
      {
        path: 'list',
        name: 'workspace-list',
        meta: {
          icon: 'md-paper',
          title: '部门列表',
          access: ['workspace.list']
        },
        component: () => import('@/view/workspace')
      },
      {
        path: 'user',
        name: 'workspace-user',
        meta: {
          icon: 'md-person',
          title: '部门用户',
          access: ['workspace.user.list']
        },
        component: () => import('@/view/workspace/component/user')
      }
    ]
  },
  {
    path: '/project',
    name: 'project',
    meta: {
      icon: 'logo-playstation',
      title: '项目管理',
      access: ['project.list']
    },
    component: Main,
    children: [
      {
        path: 'index',
        name: 'project_index',
        meta: {
          icon: 'logo-wordpress',
          title: '项目列表',
          access: ['project.list']
        },
        component: () => import('@/view/project')
      },
      {
        path: 'add',
        name: 'project_add',
        meta: {
          title: '新增项目',
          hideInMenu: true,
          access: ['project.add']
        },
        component: () => import('@/view/project/component/handle')
      },
      {
        path: 'edit/:project_id/:name',
        name: 'project_edit',
        meta: {
          title: route => `编辑项目-${route.params.name}`,
          hideInMenu: true,
          beforeCloseName: 'remove_cookie',
          access: ['project.edit']
        },
        component: () => import('@/view/project/component/handle')
      },
      {
        path: 'environment',
        name: 'environment',
        meta: {
          icon: 'ios-nuclear',
          title: '环境配置',
          access: ['environment']
        },
        component: () => import('@/view/environment')
      },
    ]
  },
  {
    path: '/deploy',
    name: 'deploy',
    component: Main,
    meta: {
      title: '部署管理',
      icon: 'md-git-compare',
      access: ['task.list']
    },
    children: [
      {
        path: 'list',
        name: 'list',
        meta: {
          icon: 'md-swap',
          title: '我的上线单',
          access: ['task.list']
        },
        component: () => import('@/view/task/component/list')
      },
      {
        path: 'submit',
        name: 'submit',
        meta: {
          icon: 'logo-twitter',
          title: '新建上线单',
          access: ['task.add']
        },
        component: () => import('@/view/task')
      },
      {
        path: 'md5',
        name: 'md5',
        meta: {
          icon: 'ios-paw',
          title: 'MD5校对',
          access: ['task.md5']
        },
        component: () => import('@/view/task/component/md5')
      },
      {
        path: 'online/:id',
        name: 'online',
        meta: {
          notCache: true,
          hideInMenu: true,
          icon: 'ios-paw',
          title: '部署项目',
          access: ['task.upload']
        },
        component: () => import('@/view/task/component/online')
      }
    ]
  },
  {
    path: '/setting',
    name: 'setting',
    meta: {
      icon: 'md-settings',
      title: '系统管理',
      access: ['system.user.info']
    },
    component: Main,
    children: [
      {
        path: '/info',
        name: 'info',
        meta: {
          icon: 'md-contacts',
          title: '个人中心',
          access: ['system.user.info']
        },
        component: () => import('@/view/user-info'),
      },
      {
        path: 'role-permission',
        name: 'role-permission',
        meta: {
          icon: 'ios-send',
          title: '权限中心',
          access: ['roles', 'permission']
        },
        children: [
          {
            path: 'role',
            name: 'role',
            component: () => import('@/view/permission/role'),
            meta: {
              title: '角色表',
              access: ['roles']
            }
          },
          {
            path: 'permission',
            name: 'permission',
            component: () => import('@/view/permission'),
            meta: {
              title: '权限表',
              access: ['permission']
            },
          }
        ],
        component: parentView,
      },
    ]
  },
  {
    path: '/401',
    name: 'error_401',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/401.vue')
  },
  {
    path: '/500',
    name: 'error_500',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/500.vue')
  },
  {
    path: '*',
    name: 'error_404',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/404.vue')
  }
]
